package test;

import java.net.*;
import java.util.Enumeration;

public class Netzwerk {

	public static InetAddress getIPAdress() {
		NetworkInterface iface = null;
		String sIPAddress = null;
		try {
			for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces
					.hasMoreElements();) {
				iface = (NetworkInterface) ifaces.nextElement();
				InetAddress ia = null;
				String ha = null;
				for (Enumeration ips = iface.getInetAddresses(); ips
						.hasMoreElements();) {
					ia = (InetAddress) ips.nextElement();
					ha = ia.getHostAddress();
					if (ha.indexOf(":") >= 0) {
						// IPv6 address
					} else if (ha.startsWith("127")) {
						// localhost address
					} else if (ha.startsWith("10.") || ha.startsWith("192.168")) {
						// private network
						return ia;
						
					} else if (ha.startsWith("192")) {
						try {
							int substr = Integer.parseInt(ha.substring(4, 7));
							if(substr > 15 && substr < 32)
								return ia;
						} catch (NumberFormatException e) {}
					}
				}
			}
		} catch (SocketException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		String ha = getIPAdress().getHostAddress();
		System.out.println(ha);
		String end = ha;
		for(int i = 0; i<3; i++)
		{
			end = end.substring(end.indexOf('.')+1, end.length()); 
			System.out.println(end);
		}
		getIPAdress().
		
		
		

	}

}
